package com.ruoyi.his.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.his.domain.TMedicalDrugsInventoryRecord;
import com.ruoyi.his.service.ITMedicalDrugsInventoryRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 盘点记录Controller
 *
 * @author ruoyi
 * @date 2021-09-10
 */
@RestController
@RequestMapping("/system/record")
public class TMedicalDrugsInventoryRecordController extends BaseController
{
    @Autowired
    private ITMedicalDrugsInventoryRecordService tMedicalDrugsInventoryRecordService;

    /**
     * 查询盘点记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMedicalDrugsInventoryRecord tMedicalDrugsInventoryRecord)
    {
        startPage();
        List<TMedicalDrugsInventoryRecord> list = tMedicalDrugsInventoryRecordService.selectTMedicalDrugsInventoryRecordList(tMedicalDrugsInventoryRecord);
        return getDataTable(list);
    }

    /**
     * 导出盘点记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "盘点记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TMedicalDrugsInventoryRecord tMedicalDrugsInventoryRecord)
    {
        List<TMedicalDrugsInventoryRecord> list = tMedicalDrugsInventoryRecordService.selectTMedicalDrugsInventoryRecordList(tMedicalDrugsInventoryRecord);
        ExcelUtil<TMedicalDrugsInventoryRecord> util = new ExcelUtil<TMedicalDrugsInventoryRecord>(TMedicalDrugsInventoryRecord.class);
        return util.exportExcel(list, "盘点记录数据");
    }

    /**
     * 获取盘点记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{recordid}")
    public AjaxResult getInfo(@PathVariable("recordid") Long recordid)
    {
        return AjaxResult.success(tMedicalDrugsInventoryRecordService.selectTMedicalDrugsInventoryRecordByRecordid(recordid));
    }

    /**
     * 新增盘点记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "盘点记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMedicalDrugsInventoryRecord tMedicalDrugsInventoryRecord)
    {
        return toAjax(tMedicalDrugsInventoryRecordService.insertTMedicalDrugsInventoryRecord(tMedicalDrugsInventoryRecord));
    }

    /**
     * 修改盘点记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "盘点记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMedicalDrugsInventoryRecord tMedicalDrugsInventoryRecord)
    {
        return toAjax(tMedicalDrugsInventoryRecordService.updateTMedicalDrugsInventoryRecord(tMedicalDrugsInventoryRecord));
    }

    /**
     * 删除盘点记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "盘点记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordids}")
    public AjaxResult remove(@PathVariable Long[] recordids)
    {
        return toAjax(tMedicalDrugsInventoryRecordService.deleteTMedicalDrugsInventoryRecordByRecordids(recordids));
    }
}
